import { createSlice } from "@reduxjs/toolkit";
const counterStore= createSlice({
    name:'counter',
    //初始化状态
    initialState:{
        count:0,
        channelList:[]
    },
    //修改状态的方法,同步方法，支持直接修改
    reducers:{
        increment:state=>{
            state.count++
        },
        decrement:state=>{
            state.count--
        },
        addToNum:(state,action)=>{
            state.count=action.payload
        },
        setChannels:(state,action)=>{
            state.channelList=action.payload
        }
    }
})
//解构出来actionCreater函数
const {increment,decrement,addToNum} = counterStore.actions
const reducer=counterStore.reducer;
export {increment,decrement,addToNum};
//导出
export default reducer